package org.springframework.boot;

import org.springframework.core.env.PropertySource;
import org.springframework.core.env.SimpleCommandLinePropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

public class Step3 {

    public static void main(String[] args) throws IOException {
        ApplicationEnvironment env = new ApplicationEnvironment();//系统环境变量，properties,yml
        //将application.properties文件添加到环境变量中
        env.getPropertySources().addLast(new ResourcePropertySource(new ClassPathResource("application.properties")));
        //添加命令行参数
        env.getPropertySources().addFirst(new SimpleCommandLinePropertySource(args));
        //遍历来源
        for (PropertySource<?> source : env.getPropertySources()) {
            System.out.println(source);
        }

        System.out.println(env.getProperty("JAVA_HOME"));
        System.out.println(env.getProperty("server.port"));
    }
}
